package org.example.pk1;

import java.util.Locale;
import java.util.Optional;

public record Student(Integer id, String name, String email, String phone) {

    /**
     * 普通实例方法
     */
    public String contactInfo() {
        return String.format("Name: %s, Email: %s, Phone: %s", name, email, phone);
    }

    public static String emailToUpperCase(String email) {
        return Optional.ofNullable(email).orElse("no email").toUpperCase(Locale.ROOT);
    }

    // 紧凑
    public Student {
        System.out.println("id="+id);
        if (id <1){
            throw new RuntimeException("id <1");
        }
    }

    // 自定义构造方法
    public Student(Integer id, String name) {
       this(id, name, null, null);
    }
}
